home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12570 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Looking for semaphore example.
  5. Date: 1 Apr 1996 08:08:22 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4jov1mINNki@keats.ugrad.cs.ubc.ca>
  8. References: <4jc5hd$1vlv@ilx018.iil.intel.com> <828220289snz@genesis.demon.co.uk> <4jlc0k$j02@solutions.solon.com>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4jlc0k$j02@solutions.solon.com>,
  12. Peter Seebach <seebs@solutions.solon.com> wrote:
  13. >In article <828220289snz@genesis.demon.co.uk>,
  14. >Lawrence Kirby  <fred@genesis.demon.co.uk> wrote:
  15. >>>Hi - 
  16. >>>I'm looking for a simple example of implementation of semaphore in C .
  17. >
  18. >>Not possible - the C language doesn't support semaphores. You'll have
  19. >>to go beyond the C language to get this.
  20. >
  21. >Nonsense!  You'll just need to go beyond the C language to implement
  22. >semaphores in a useful or meaningful way.  :)  You could easily implement
  23. >a semaphore algorithm in C, it just wouldn't matter in pure C, because
  24. >you'd only ever have the one process.
  25.  
  26. How would you do it?. A semaphore is by definition a shared object between two
  27. processes for the purpose of synchronization, and not just some ordinary
  28. variable. Interprocess communication and synchronization is outside of the
  29. scope of the C language proper.
  30.  
  31. By the way, what is the Standard C answer to the test-and-set operation? I
  32. don't think that there is an atomic test-and-set in the C language, so I don't
  33. see how you have any hope of implementing a semaphore algorithm in pure C that
  34. would have any hope of working race-free in a threaded environment. Even
  35. blocking signals is outside of the scope of standard C, not to mention
  36. disabling machine interrupts or doing bus locking. Hmm.
  37. -- 
  38.  
  39.